package cn.edu.sdu.sduhour.controller;

import cn.edu.sdu.sduhour.entity.State;
import cn.edu.sdu.sduhour.mapper.StateMapper;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/state")
public class StateController {
    @Resource
    StateMapper stateMapper;

    //获取所有的状态记录（管理员）
    /*传入：null*/
    @GetMapping("/all")
    public List<State> findAll() {
        return stateMapper.findAll();
    }

    //获取某人的状态记录
    /*传入：String openid;*/
    @PostMapping("/one")
    public List<State> findOne(@RequestBody State state) {
        return stateMapper.findOne(state);
    }

    //新增一条状态记录
    /*传入：String openid;*/
    @PostMapping("/add")
    public List<State> addOne(@RequestBody State state) {
        stateMapper.addOne(state);
        return stateMapper.findOne(state);
    }

    //更改一条状态记录
    /*传入：
    * String openid;
    * String changeName;
    * */
    @PostMapping("/set")
    public List<State> setOne(@RequestBody State state) {
        stateMapper.setOne(state);
        return stateMapper.findOne(state);
    }

    //删除一条状态记录（管理员）
    /*传入：int id;*/
    @DeleteMapping("/del")
    public String delOne(@RequestBody State state) {
        stateMapper.delOne(state);
        return "success";
    }
}
